import { debug } from 'webpack'
import { AppModel } from '../../../../model/AppModel'
import { createPartMenu, createVarMenu } from '../BlockPackage'

declare var Vue : any


export default {

    category: Blockly.Categories.bepart ,
    
    color: [
        Blockly.Colours.bepart.primary,
        Blockly.Colours.bepart.secondary,
        Blockly.Colours.bepart.tertiary
    ] ,

    previousStatement: true ,
    nextStatement: true ,
    inputsInline: false,

    init(model:Model, scratch3:any) {
        this.appendDummyInput()
            .appendField("读取字符串保存至变量")
            .appendField(createVarMenu(scratch3), 'var')
    } ,

    run (args: any, util: any, runtime: any, model: AppModel) {} ,

    coder: {
        JavaScript(block: any, coder: any, model: AppModel) {
            let indent = coder.indentString()
            let varname = block.getFieldValue('var')
            let code = `${indent}be.var["${varname}"] = beapi.utils.unpackString(_pkg_buff, _pkg_offset)\n`
            code+= `${indent}_pkg_offset+= beapi.utils.stringBytes(be.var["${varname}"])+1\n`
            code+= `\n`
            return code
        }
    }
}
